package list.trst.Demo4;

import java.util.Random;

public class RandomNumberDemo {
    public static void main(String[] args) {
        //匿名内部类方法
        useRandomNumber(new RandomNumber() {
            @Override
            public int getNumber() {
                Random r = new Random();
                int num = r.nextInt(10) + 1;
                return num;
            }
        });


        //lambda方法
        useRandomNumber(()->{
            Random r = new Random();
            int num = r.nextInt(10) + 1;
            return num;
        });

        RandomNumber r1 = ()->{
            Random r = new Random();
            int num = r.nextInt(10) + 1;
            return num;
        };
        useRandomNumber(r1);
    }

    public static void useRandomNumber(RandomNumber rn) {
        int result = rn.getNumber();
        System.out.println(result);
    }
}
